﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using Helper.Bussiness;
using com.SEO.Model;

namespace SEO_Server.Pages.User
{
    public partial class AddUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region Page Events

        /// <summary>
        /// Close Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnClose_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.GetHidePostBackReference());
        }

        /// <summary>
        /// Enter Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEnter_Click(object sender, EventArgs e)
        {
            // Check if the same account is exists or not.
            UserManage userManage = new UserManage();
            List<UserInfo> lstUsers = userManage.GetUserByCondition(" UserAccount = '" + tbxUserAccount.Text.Trim() + "'");
            if (lstUsers.Count > 0)
            {
                Alert.Show("該帳號已經存在!");
                return;
            }

            UserInfo info = new UserInfo();
            info.UserId = Guid.NewGuid();
            info.UserAccount = tbxUserAccount.Text.Trim();
            info.UserPassword = "123456";
            info.UserQQ = tbxUserQQ.Text.Trim();
            info.UserType = true;

            int result = userManage.AddUserInfo(info);
            if (result == -1)
            {
                this.btnClose_Click(null, null);
            }
            else
            {
                Alert.Show("添加帳戶失敗!");
            }
        }

        #endregion
    }
}